Skip to content

More rules are missing named arguments - #7040

Merged
staabm merged 8 commits into
phpstan:2.3.xfrom
staabm:nameds
Nov 12, 2026
Merged

staabm merged 8 commits into
phpstan:2.3.xfrom
staabm:nameds

Conversation

@staabm

@staabm staabm commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

followup to #7028

@staabm
staabm marked this pull request as ready for review November 11, 2026 20:02
@phpstan-bot

Copy link
Copy Markdown
Collaborator

This pull request has been marked as ready for review.

@staabm

staabm commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

//cc @SanderMuller

@SanderMuller SanderMuller left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The named-argument changes work. Each of the three new test expectations fails on 2.3.x (527d373) and passes on 2cb886b. On 2cb886b the full test suite, make phpstan and phpcs on the changed files also pass.

I would not remove treatPhpDocTypesAsCertain from ImpossibleInArrayHaystackFiniteTypesRule. This rule reports haystack values that can never match the needle. In #7007, Ondřej said that the flag is there to relax that kind of report when it is false. ReplaceCountMismatchRule is a different case, because it checks argument types.

Without the flag, the output changes in two directions (level 8, bleedingEdge):

/** @param 'a'|'b' $s */
function phpDocOnlyImpossible(string $s): void
{
	array_search($s, ['c'], true); // line 8
}

/** @param true $strict */
function phpDocStrict(int $i, bool $strict): void
{
	array_search($i, ['1', 1, 2], $strict); // line 14
}
  • With treatPhpDocTypesAsCertain: false, this PR reports line 8. 2.3.x does not, because the native type of the needle is string.
  • With the default true, this PR no longer reports line 14. 2.3.x reports it. The strict argument now always uses its native type bool, so the true from the PHPDoc is lost.

The Shopware integration job is red on this PR. It is green on #7038 and #7039 from today. Shopware sets treatPhpDocTypesAsCertain: false. Two of the new errors come from this change: Value null and Value false in the haystack passed to in_array() in DefinitionValidator.php. In a small copy of that in_array() call, this PR reports both errors with the flag off, and 2.3.x does not. The third new error, random_int in ProductGenerator.php, is also reported on 2.3.x, so it does not come from this PR.

I suggest that you keep the reorderFuncArguments() part and restore the flag handling as it was. That is getType() when the flag is true and getNativeType() when it is false, for the needle, the haystack and the strict argument.

Things I checked that are fine:

  • array_keys(array: [...], strict: true) without filter_value reports nothing. Your test covers this.
  • getTemplateType() with named arguments in reverse order is reported. Before this PR it was not.

Performance: I ran src/Rules (734 files, level 8, bleedingEdge, --debug, no result cache) 6 times on each side. The mean user CPU was 17.9 s on 2.3.x and 17.6 s on this PR. The wall time varied from 19 s to 36 s within one side, so I see no measurable difference.

@staabm

staabm commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor Author

Without the flag, the output changes in two directions (level 8, bleedingEdge):

thank you for the examples. I just added the tests and reverted to use the treatPhpDocTypesAsCertain logic again

@staabm
staabm merged commit 277e41a into phpstan:2.3.x Nov 12, 2026
886 of 892 checks passed
@staabm
staabm deleted the nameds branch November 12, 2026 07:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants